package com.sm.healthy.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.sm.healthy.R
import com.sm.healthy.utils.DateUtils

@BindingAdapter("header")
fun setHeaderImg(iv: ImageView, header: String?) {
    when (header) {
        "1" -> Glide.with(iv.context).load(R.mipmap.icon_header_old_man).into(iv)
        "2" -> Glide.with(iv.context).load(R.mipmap.icon_header_man).into(iv)
        "3" -> Glide.with(iv.context).load(R.mipmap.icon_header_boy).into(iv)
        "4" -> Glide.with(iv.context).load(R.mipmap.icon_header_old_women).into(iv)
        "5" -> Glide.with(iv.context).load(R.mipmap.icon_header_women).into(iv)
        "6" -> Glide.with(iv.context).load(R.mipmap.icon_header_girl).into(iv)
        "0" -> Glide.with(iv.context).load(R.mipmap.icon_header_none).into(iv)
    }
}

@BindingAdapter("roleVale")
fun setRoleVale(textView: TextView, roleVale: String?) {
    val role: String =
        String.format(textView.context.getString(R.string.text_role), roleVale)
    textView.text = role
}

@BindingAdapter("itemName")
fun setName(textView: TextView, name: String?) {
    val role: String = String.format(textView.context.getString(R.string.text_name), name)
    textView.text = role
}

@BindingAdapter("itemAge")
fun setAge(textView: TextView, age: String?) {
    val role: String =
        String.format(textView.context.getString(R.string.text_age), age)
    textView.text = role
}

@BindingAdapter("itemMobile")
fun setMobile(textView: TextView, mobile: String?) {
    val role: String =
        String.format(textView.context.getString(R.string.text_mobile), mobile)
    textView.text = role
}

@BindingAdapter("itemMeasureTime")
fun setMeasureTime(textView: TextView, measureTime: String?) {
    textView.text = measureTime
}

@BindingAdapter("itemSystolic")
fun setSystolic(textView: TextView, systolic: String?) {
    textView.text = systolic
}

@BindingAdapter("itemEcgMeasureTime")
fun setEcgMeasureTime(textView: TextView, timeLong: String?) {
    textView.text = timeLong?.toLong()?.let { DateUtils.getTime(it) }
}

@BindingAdapter("itemDiastolic")
fun setDiastolic(textView: TextView, diastolic: String?) {
    textView.text = diastolic
}

@BindingAdapter("itemPulseRate")
fun setPulseRate(textView: TextView, pulseRate: String?) {
    textView.text = pulseRate
}

